﻿@model OJS.Web.ViewModels.News.AllNewsViewModel
@using Resource = Resources.News.Views.All;

@{
    ViewBag.Title = Resource.Title;
}

<h2>@ViewBag.Title</h2>

@if (!Model.AllNews.Any())
{
    <p>@Resource.No_news.</p>
}
else
{
    <table class="table table-hover">
        <tr class="col-md-12">
            <td>
                <span class="col-md-4">@Resource.News_title</span>
                <span class="col-md-3">@Resource.Author</span>
                <span class="col-md-3">@Resource.Source</span>
                @Resource.Date
            </td>
        </tr>
        @foreach (var news in Model.AllNews)
        {
            <tr class="col-md-12">
                <td class="text-primary">
                    <span class="col-md-4"><a href="/News/Selected/@news.Id">@news.Title</a></span>
                    <span class="col-md-3">@news.Author</span>
                    <span class="col-md-3">@news.Source</span>
                    @news.TimeCreated.ToString("dd/MM/yyyy")
                </td>
            </tr>
        }
    </table>

    <div class="row text-center">
        <div class="btn-group">
            @{
    if (Model.CurrentPage <= 1)
    {
        <span class="btn btn-primary" disabled="disabled"><<</span>
                <span class="btn btn-primary" disabled="disabled"><</span>
    }
    else
    {
        @Html.ActionLink("<<", "All", new { id = 1 }, new { @class = "btn btn-primary" })
        @Html.ActionLink("<", "All", new { id = Model.CurrentPage - 1 }, new { @class = "btn btn-primary" })
    }
            }

            @{
    int startPage = 1;
    int endPage = Model.AllPages;

    if (Model.AllPages > 10)
    {
        if (Model.CurrentPage > 5)
        {
            startPage = Model.CurrentPage - 5;
        }

        if (Model.CurrentPage + 5 < Model.AllPages)
        {
            endPage = Model.CurrentPage + 5;
        }
    }
            }

            @{
    if (Model.CurrentPage - 5 > 1)
    {
        <span class="btn btn-primary" disabled="disabled">...</span>
    }
            }

            @for (int pageIndex = startPage; pageIndex <= endPage; pageIndex++)
            {
                if (pageIndex != Model.CurrentPage)
                {
                    @Html.ActionLink(pageIndex.ToString(), "All", new { controller = "News", area = string.Empty, id = pageIndex }, new { @class = "btn btn-primary" })
                }
                else
                {
                    <span class="btn btn-primary" disabled="disabled">@pageIndex</span>
                }
            }

            @{
    if (Model.CurrentPage + 5 < Model.AllPages)
    {
        <span class="btn btn-primary" disabled="disabled">...</span>
    }
            }

            @{
    if (Model.CurrentPage >= Model.AllPages)
    {
        <span class="btn btn-primary" disabled="disabled">></span>
                <span class="btn btn-primary" disabled="disabled">>></span>
    }
    else
    {
        @Html.ActionLink(">", "All", new { id = Model.CurrentPage + 1 }, new { @class = "btn btn-primary" })
                @Html.ActionLink(">>", "All", new { id = Model.AllPages }, new { @class = "btn btn-primary" })
    }
            }

        </div>
    </div>
}